//
//  YXMachineDetailsTableView.m
//  CreditCard
//
//  Created by 杨旭 on 2017/12/24.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "YXMachineDetailsTableView.h"
#import "YXMachineMaterialCell.h"
#import "YXMachinesModel.h"
@interface YXMachineDetailsTableView ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic ,strong) UIView *footerView;
@property (nonatomic ,strong) UILabel *titleLab;
@property (nonatomic ,strong) UILabel *contentLab1;
@property (nonatomic ,strong) UILabel *contentLab2;
@property (nonatomic ,strong) UILabel *contentLab3;

@end
@implementation YXMachineDetailsTableView

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel setLabelWithText:@"功能特性" fontSize:16 color:color_globalColor];
        _titleLab.frame = CGRectMake(15, 10, kScreenWidth - 30, 20);
    }
    return _titleLab;
}
- (UILabel *)contentLab1 {
    if (!_contentLab1) {
        _contentLab1 = [UILabel setLabelWithText:@"" fontSize:12 color:color_textOne];
        _contentLab1.lineBreakMode = NSLineBreakByWordWrapping;
        _contentLab1.numberOfLines = 0;
    }
    return _contentLab1;
}

- (UILabel *)contentLab2 {
    if (!_contentLab2) {
        _contentLab2 = [UILabel setLabelWithText:@"" fontSize:12 color:color_textOne];
        _contentLab2.lineBreakMode = NSLineBreakByWordWrapping;
        _contentLab2.numberOfLines = 0;
    }
    return _contentLab2;
}

- (UILabel *)contentLab3 {
    if (!_contentLab3) {
        _contentLab3 = [UILabel setLabelWithText:@"" fontSize:12 color:color_textOne];
        _contentLab3.lineBreakMode = NSLineBreakByWordWrapping;
        _contentLab3.numberOfLines = 0;
    }
    return _contentLab3;
}

- (UIView *)footerView {
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, kScreenWidth, 300))];
        [_footerView addSubview:self.titleLab];
        [_footerView addSubview:self.contentLab1];
        [_footerView addSubview:self.contentLab2];
        [_footerView addSubview:self.contentLab3];
        [_contentLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLab.mas_bottom).offset(10);
            make.left.equalTo(_footerView.mas_left).offset(15);
            make.right.equalTo(_footerView.mas_right).offset(-15);
        }];
        [_contentLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_contentLab1.mas_bottom).offset(5);
            make.left.equalTo(_footerView.mas_left).offset(15);
            make.right.equalTo(_footerView.mas_right).offset(-15);
        }];
        [_contentLab3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_contentLab2.mas_bottom).offset(5);
            make.left.equalTo(_footerView.mas_left).offset(15);
            make.right.equalTo(_footerView.mas_right).offset(-15);
        }];
        
    }
    return _footerView;
}

- (void)setDetailsModel:(YXMachinesModel *)detailsModel {
    _detailsModel = detailsModel;
    
    NSString *explains = detailsModel.explains;
    NSArray *array = [explains componentsSeparatedByString:@"\n"];
//    NSLog(@"%@ -- %@ -- %@",array[0],array[1],array[1]);
    self.titleLab.text = array[0];
    self.contentLab1.text = array[1];
    self.contentLab2.text = array[2];
    self.contentLab3.text = array[3];
    
    [self reloadData];
}

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    if (self = [super initWithFrame:frame style:style]) {
        self.backgroundColor = color_backColor;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
        self.dataSource = self;
        self.delegate = self;
        self.tableFooterView = self.footerView;
    }
    return self;
}

#pragma mark - UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString * cellId = @"YXMachineMaterialCell";
    YXMachineMaterialCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell==nil) {
        cell=[[[NSBundle mainBundle]loadNibNamed:cellId owner:self options:nil] lastObject];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    cell.detailsModel = self.detailsModel;
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 262;
}


@end
